package com.example.springboot1.controller;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;


@RestController  //等价于上面两个
public class HelloController {


    @GetMapping("/hello")
    public String hello(){
        return "Hello SpringBoot"+ nameAges.toString();
    }

    private static HashMap<String, Integer> nameAges = new HashMap<>();

    @PostMapping("/hello")
    public String helloPost(String name, int age){
        nameAges.put(name, age);
        return "add name: "+ name + ", age "+age;
    }

    @PutMapping("/hello")
    public String helloPut(String name, int age){
        nameAges.replace(name, age);
        return "update name: "+ name + ", age "+age;
    }

    @DeleteMapping("/hello/{name}")
    public String helloDel(@PathVariable String name){
        nameAges.remove(name);
        return "delete name: "+ name;
    }
}
